
#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        int i = 0;
        int n = pushed.size();
        stack<int> st;
        for (auto& e : pushed)
        {
            st.push(e);
            while (!st.empty() && popped[i] == st.top())
            {
                st.pop();
                i++;
            }
        }
        return st.empty();
    }
};